package com.bw.controller;

import com.bw.entity.Bing;
import com.bw.entity.Zhexiantu;
import com.bw.mapper.StudentMapper;
import org.spring.kun.common.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
//@RestController // 给所有的方法加上 @ResponseBody注解
public class EchartsController {

    @Autowired
    StudentMapper studentMapper;


    @RequestMapping("/echartsPage.do")
    public String echartsPage(){

        return "echartsPage";
    }

    /**
     *  折线图  根据小组过滤数据，然后再统计
     * @return
     */
    @RequestMapping("/stuCountByGroup.do")
    @ResponseBody // 把返回值 序列化为Json字符串格式
    public List<Zhexiantu> stuCountByGroup(Integer group){

        List<Zhexiantu> list = studentMapper.stuCountByGroup(group);

        return list;

    }
    /**
     *  折线图  柱状图使用
     * @return
     */
    @RequestMapping("/stuCount.do")
    @ResponseBody // 把返回值 序列化为Json字符串格式
    public List<Zhexiantu> stuCount(){

        List<Zhexiantu> list = studentMapper.stuCount();

        return list;

    }


    /**
     * 饼状图使用
     * @return
     */
    @RequestMapping("/bing.do")
    @ResponseBody // 把返回值 序列化为Json字符串格式
    public List<Bing> bing(){

        List<Bing> list = studentMapper.bing();

        return list;

    }

    /**
     * excel导出
     * @return
     */
    @RequestMapping("/excel.do")
    public void excel(Integer group,HttpServletResponse response){
        // 先查询数据
        List<Zhexiantu> list = studentMapper.stuCountByGroup(group);

        ExcelUtils.exportExcel(list,"学生数量导出","学生数量",response);


    }
}
